package com.raychi.demo.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcUtil {
	
	private static final String DBDRIVER = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://127.0.0.1/demo";
	private static final String USER = "root";
	private static final String PASS = "mysql";
	
	public static Connection getConnection() throws SQLException, ClassNotFoundException {
		Class.forName(DBDRIVER);
		Connection conn = null;
		conn = DriverManager.getConnection(URL, USER, PASS);
		conn.setAutoCommit(false);
		return conn;
	}
	
	public static void closeConnection(Connection conn) {
		if (conn != null)
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}
	
	public static void rollback(Connection conn) {
		if (conn != null)
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}

}
